/* -*- mode: c++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- */

#ifndef _TCPSERVER_H_
#define _TCPSERVER_H_

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <sys/time.h>

class ClientInfo {
public:
    int                         fd;

    sockaddr_in                 addr;
};

class TcpServer {
public:
    int                         fd;

    int                         port;

    fd_set                      rfds;

    TcpServer() : fd(-1), port(-1)
    {
    }

    ~TcpServer() {
        if (fd >= 0)
            close(fd);
    }

    bool init(int p);

    bool try_accept(int max_wait, ClientInfo& ci);
};

#endif /* _TCPSERVER_H_ */
